package com.teacherprofile.manage.controller;

import com.teacherprofile.manage.config.ChatRedisMemory;
import com.teacherprofile.manage.domain.vo.MessageVO;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("agent/history")
public class ChatHistoryController {
    @Autowired
    private ChatRedisMemory chatMemory;


    @GetMapping("{chatId}")
    public List<MessageVO> listHistory(@PathVariable("chatId") String chatId) {
        List<Message> messages = chatMemory.get(chatId, Integer.MAX_VALUE);
        if (messages == null) {
            return List.of();
        }
        return messages.stream().map(MessageVO::new).collect(Collectors.toList());
    }
    @DeleteMapping("{chatId}")
    public void deleteHistory(@PathVariable("chatId") String chatId) {
        chatMemory.clear(chatId);
    }
}
